<template>
  <view class="container">
    <view class="form-wrapper">
      <text class="title">注册</text>

      <input 
        class="input-item" 
        type="text" 
        placeholder="请输入用户名" 
        v-model="username" 
        placeholder-class="placeholder-style"
      />

      <input 
        class="input-item" 
        type="password" 
        placeholder="请输入密码（至少6位）" 
        v-model="password" 
        placeholder-class="placeholder-style"
      />

      <input 
        class="input-item" 
        type="password" 
        placeholder="请确认密码" 
        v-model="confirmPassword" 
        placeholder-class="placeholder-style"
      />

      <button 
        class="btn register-btn" 
        type="primary" 
        @click="handleRegister"
        :loading="isLoading"
      >
        注册
      </button>

      <view class="link-group">
        <text class="link-text">已有账号？</text>
        <navigator 
          url="/pages/Login/Login" 
          class="nav-link"
        >
          去登录
        </navigator>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      username: '', 
      password: '', 
      confirmPassword: '', 
      isLoading: false 
    };
  },
  methods: {
    handleRegister() {
      if (!this.username.trim()) {
        return this.showToast('请输入用户名');
      }
      if (this.password.length < 6) {
        return this.showToast('密码长度至少6位');
      }
      if (this.password !== this.confirmPassword) {
        return this.showToast('两次密码输入不一致');
      }
      this.isLoading = true;

      setTimeout(() => {
        this.isLoading = false;
        this.showToast('注册成功', 'success');

        setTimeout(() => {
          uni.navigateBack({
            delta: 1 
          });
        }, 1000);
      }, 1500);
    },

    showToast(title, icon = 'none') {
      uni.showToast({
        title,
        icon,
        duration: 2000
      });
    }
  }
};
</script>

<style scoped>
.container {
  display: flex;
  justify-content: center;
  padding-top: 100rpx;
  padding-bottom: 120px;
  background-color: #f5f5f5;
  min-height: 100vh;
  box-sizing: border-box;
}

.form-wrapper {
  width: 90%;
  max-width: 500rpx;
  background-color: #fff;
  padding: 60rpx 40rpx;
  border-radius: 16rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
}

.title {
  display: block;
  text-align: center;
  font-size: 36rpx;
  font-weight: bold;
  color: #333;
  margin-bottom: 60rpx;
}

.input-item {
  width: 100%;
  height: 90rpx;
  padding: 0 20rpx;
  margin-bottom: 30rpx;
  border: 1px solid #eee;
  border-radius: 8rpx;
  font-size: 28rpx;
  box-sizing: border-box;
}

.placeholder-style {
  color: #999;
}

.btn {
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  font-size: 30rpx;
  border-radius: 8rpx;
  margin-bottom: 40rpx;
}

.register-btn {
  background-color: #007aff;
}
.register-btn:active {
  background-color: #0066cc;
}

.link-group {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 26rpx;
}

.link-text {
  color: #666;
}

.nav-link {
  color: #007aff;
  margin-left: 10rpx;
  text-decoration: none;
}
</style>